//Function to set text from FreeTextBox on a popup window to a specific control on the parent form. 
//The name of the control (on the parent form) is stored in a hidden field (name 'parentControl')
function SendData()
{
	var parentControl = document.getElementById('parentControl');
	var ftbText = FTB_API['itemText'].GetHtml();
	
	var reg = new RegExp("(<(p|P)>)(.*)(</(p|P)>)", "i");
	
	//find paragraph in html
	var match = reg.exec(ftbText);
	
	//The following line will help understand the groups that are extracted from a single match
	//alert(match.index + ' ' + match.input + ' ' + match[0] + ' ' + match[1] + ' ' + match[2] + ' ' + match[3] + ' ' + match[4] + ' ' + match[5]);
	
	//remove the first paragraph tags
	if (match!= null && match.index == 0)
	{
		ftbText = ftbText.replace(reg, "$3");
	}
	
	//for the subsequent paragraph tags, replace them with a break. $3 will give the text within <p> and </p>
	//if, after replacing the paragraph tags with a break, the item option is again edited to add a new line of text, 
	//then paragraph tags are again appended by FTB. This problem is rectified by "(<BR>)?" in the regex
	reg = new RegExp("(<(p|P)>(<BR>)?)(.*)(</(p|P)>)", "ig");
	ftbText = ftbText.replace(reg, "<BR>$4");

	window.opener.document.getElementById(parentControl.value).value = ftbText;
	window.close();
}